package com.zs.blog.controller;

import com.zs.blog.model.ResponseResult;
import com.zs.blog.model.dto.AuthorityEditDTO;
import com.zs.blog.model.dto.AuthoritySearchDTO;
import com.zs.blog.model.vo.AuthorityLabelListVO;
import com.zs.blog.model.vo.AuthorityListVO;
import com.zs.blog.model.vo.PageInfoVO;
import com.zs.blog.service.IAuthorityService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: AuthorityController
 * @Author zs
 * @Package com.zs.blog.controller
 * @Date 2025/9/2 21:16
 * @description: 权限接口层
 */
@RestController
public class AuthorityController {

    public IAuthorityService authorityService;

    @Autowired
    public AuthorityController(IAuthorityService authorityService){
        this.authorityService = authorityService;
    }

    @GetMapping("/admin/authority/level/list")
    @Operation(description = "获取系统资源权限层级信息列表")
    public ResponseResult<List<AuthorityLabelListVO>> listAuthorityLevelInfo(){
        List<AuthorityLabelListVO> listAuthorityLevel = authorityService.listAuthorityLevelInfo();
        return ResponseResult.success(listAuthorityLevel);
    }

    @GetMapping("/admin/authority/list")
    @Operation(description = "获取分页的权限列表信息")
    public ResponseResult<PageInfoVO<AuthorityListVO>> listAuthorityWithPagination(Integer pageNum, Integer pageSize){
        PageInfoVO<AuthorityListVO> listAllAuthority = authorityService.listAuthorityWithPagination(pageNum,pageSize);
        return ResponseResult.success(listAllAuthority);
    }

    @PostMapping("/admin/authority/add")
    @Operation(description = "新增权限信息")
    public ResponseResult<?> addAuthority(@RequestBody AuthorityEditDTO authorityEditDTO){
        authorityService.addAuthority(authorityEditDTO);
        return ResponseResult.success();
    }

    @PutMapping("/admin/authority/delete")
    @Operation(description = "删除权限信息")
    public ResponseResult<?> deleteAuthority(@RequestBody List<Long> authorityIds){
        authorityService.deleteAuthority(authorityIds);
        return ResponseResult.success();
    }

    @PostMapping("/admin/authority/search")
    @Operation(description = "通过搜索条件查询分页的角色列表")
    public ResponseResult<PageInfoVO<AuthorityListVO>> listAuthorityBySearchCondition(@RequestBody AuthoritySearchDTO authoritySearchDTO){
        PageInfoVO<AuthorityListVO> listAuthority = authorityService.listAuthorityBySearchCondition(authoritySearchDTO);
        return ResponseResult.success(listAuthority);
    }

}
